﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentNHibernate.Automapping;
using FluentNHibernate.Automapping.Alterations;
using Peak.Core;

namespace Peak.Data.NHibernateMaps
{
  public class ProjectMap : IAutoMappingOverride<Project>
  {
    public void Override(AutoMapping<Project> mapping)
    {
      mapping.Id(x => x.Id, "id").UnsavedValue(0).GeneratedBy.Identity();
      mapping.Map(x => x.Name).Not.Nullable();
      mapping.Map(x => x.Vision);
      mapping.Map(x => x.DefinitionOfDone);
      mapping.Map(x => x.Start);
      mapping.Map(x => x.End);
      mapping.Map(x => x.Created).Not.Nullable();
      mapping.Map(x => x.CreatedBy);
      mapping.Map(x => x.CurrentEffort);     
      mapping.HasMany(x => x.Sprints).Cascade.All();
      mapping.HasMany(x => x.Stories).Cascade.All();
      mapping.HasMany(x => x.Burndown).Cascade.All();
      mapping.HasManyToMany(x => x.Users).Cascade.SaveUpdate();
      mapping.HasOne(x => x.Calendar).Cascade.All();
      //mapping.References(x => x.Owner);//.Not.Nullable();
    }
  }
}